/*    */ package cc.s2m.web.s2mBlog.util;
/*    */ 
/*    */ import net.spy.memcached.MemcachedClient;
/*    */ import org.apache.commons.codec.digest.DigestUtils;
/*    */ import org.springframework.cache.Cache;
/*    */ import org.springframework.cache.Cache.ValueWrapper;
/*    */ import org.springframework.cache.support.SimpleValueWrapper;
/*    */ 
/*    */ public class MemcacheCache
/*    */   implements Cache
/*    */ {
/*    */   private MemcachedClient client;
/*    */   private String name;
/*    */ 
/*    */   public MemcacheCache()
/*    */   {
/*    */   }
/*    */ 
/*    */   public MemcacheCache(String name, MemcachedClient client)
/*    */   {
/* 19 */     this.client = client;
/* 20 */     this.name = name;
/*    */   }
/*    */ 
/*    */   public String getName()
/*    */   {
/* 25 */     return this.name;
/*    */   }
/*    */ 
/*    */   public Object getNativeCache()
/*    */   {
/* 30 */     return this.client;
/*    */   }
/*    */ 
/*    */   public Cache.ValueWrapper get(Object key)
/*    */   {
/* 35 */     Object value = this.client.get(objectToString(key));
/* 36 */     return value != null ? new SimpleValueWrapper(value) : null;
/*    */   }
/*    */ 
/*    */   public <T> T get(Object key, Class<T> type)
/*    */   {
/* 41 */     throw new IllegalArgumentException("未实现的方法");
/*    */   }
/*    */ 
/*    */   public void put(Object key, Object value)
/*    */   {
/* 46 */     if (value == null) {
/* 47 */       return;
/*    */     }
/* 49 */     this.client.set(objectToString(key), 3600, value);
/*    */   }
/*    */ 
/*    */   public Cache.ValueWrapper putIfAbsent(Object key, Object value)
/*    */   {
/* 54 */     throw new IllegalArgumentException("未实现的方法");
/*    */   }
/*    */ 
/*    */   public void evict(Object key)
/*    */   {
/* 59 */     this.client.delete(objectToString(key));
/*    */   }
/*    */ 
/*    */   public void clear()
/*    */   {
/* 64 */     throw new IllegalArgumentException("未实现的方法");
/*    */   }
/*    */ 
/*    */   private static String objectToString(Object object) {
/* 68 */     if (object == null)
/* 69 */       return null;
/* 70 */     if ((object instanceof String)) {
/* 71 */       return DigestUtils.md5Hex((String)object);
/*    */     }
/* 73 */     return DigestUtils.md5Hex(object.toString());
/*    */   }
/*    */ 
/*    */   public void setClient(MemcachedClient client)
/*    */   {
/* 78 */     this.client = client;
/*    */   }
/*    */ 
/*    */   public MemcachedClient getClient() {
/* 82 */     return this.client;
/*    */   }
/*    */ 
/*    */   public void setName(String name) {
/* 86 */     this.name = name;
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.util.MemcacheCache
 * JD-Core Version:    0.6.1
 */